package com.zsj.hello.four;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;
import com.zsj.hello.util.RabbimqFactoryUtil;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/**
 * @author https://gitee.com/zhengshengjun
 * @date 2023/8/30.
 */
public class Task2 {

    public static final String ACK_QUEUE_NAME = "ack_queue";

    public static void main(String[] args) throws IOException, TimeoutException {

        Channel channel = RabbimqFactoryUtil.getRabbitMQChannel();
        //声明新队列
        //durable 是否为持久化队列
        channel.queueDeclare(ACK_QUEUE_NAME, true, false, false, null);



        //发送消息 从控制台接收
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String message = scanner.next();
            //消息持久化
            channel.basicPublish("", ACK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
            System.out.println("生产者发出消息" + message);

        }

    }
}
